package com.voute.View.Activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.text.TextUtils;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.afollestad.materialdialogs.MaterialDialog;
import com.voute.App.App;
import com.voute.Base.BaseActivity;
import com.voute.Base.BaseFragment;
import com.voute.R;
import com.voute.Utils.ViewUtils;
import com.voute.View.Adapter.NewHotCommentsFragmentAdapter;
import com.voute.View.Fragement.CommentsFragment;

import java.util.ArrayList;
import java.util.List;

/**
 * 新的评论Activity
 * Created by liucxu on 2017/3/7.
 */

public class CommentsActivity extends BaseActivity{

    private RelativeLayout back_layout;
    private TextView tv_title;
    private TabLayout tab_layout;
    private ViewPager view_pager;
    private TextView tv_instant_comment;

    private MaterialDialog progressDialog;

    private List<BaseFragment> fragments = new ArrayList<>();
    private List<String> titles = new ArrayList<>();
    private NewHotCommentsFragmentAdapter adapter;

    private String fid="";
    private boolean is_positive=true;

    @Override
    public int getLayoutId() {
        return R.layout.activity_comments;
    }

    @Override
    public void setupView() {
        back_layout=$(R.id.back_layout);
        tv_title=$(R.id.tv_title);
        tab_layout=$(R.id.tab_layout);
        view_pager=$(R.id.view_pager);
        tv_instant_comment=$(R.id.tv_instant_comment);
        back_layout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                App.GetInstance().finishActivity(CommentsActivity.this);
            }
        });
    }

    @Override
    public void setupData() {
        fid=getIntent().getStringExtra("key_fid");
        if(TextUtils.isEmpty(fid)){
            App.GetInstance().finishActivity(CommentsActivity.this);
        }
        String comments_num=getIntent().getStringExtra("key_num_comments");
        tv_title.setText("评论("+comments_num+")");
        is_positive=getIntent().getBooleanExtra("is_positive",true);
        tv_instant_comment.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(CommentsActivity.this, PostCommentsActivity.class);
                intent.putExtra("key_fid", fid);
                intent.putExtra("is_positive", is_positive);
                CommentsActivity.this.startActivity(intent);
            }
        });
        fragments.clear();
        titles.clear();
        BaseFragment discoveryFragment = ViewUtils.createFragment(CommentsFragment.class, false);
        Bundle bundle_movie = new Bundle();
        bundle_movie.putString("comment_type", "new_comment");
        bundle_movie.putString("fid",fid);
        discoveryFragment.setArguments(bundle_movie);
        BaseFragment localFragment = ViewUtils.createFragment(CommentsFragment.class, false);
        Bundle bundle_tv = new Bundle();
        bundle_tv.putString("comment_type", "hot_comment");
        bundle_tv.putString("fid",fid);
        localFragment.setArguments(bundle_tv);
        fragments.add(discoveryFragment);
        fragments.add(localFragment);
        titles.add("最新评论");
        titles.add("最热评论");
        adapter = new NewHotCommentsFragmentAdapter(getSupportFragmentManager(), titles, fragments);
        view_pager.setAdapter(adapter);
        tab_layout.setupWithViewPager(view_pager);
        tab_layout.setTabsFromPagerAdapter(adapter);
    }
}
